package cn.org.xuanguang.kepler.hormos.orm.acl;

import cn.org.xuanguang.kepler.hormos.orm.acl.impl.DataPermissionPolicy;
import cn.org.xuanguang.kepler.hormos.orm.acl.impl.RowPermissionPolicy;
import cn.org.xuanguang.kepler.hormos.orm.acl.impl.TenantPolicy;
import cn.org.xuanguang.kepler.hormos.rdb.dml.operator.AbstractOperatorParameter;

/**
 * 策略提供器
 * 提供分别满足，租户，数据权限、行权限、数据集权限的策略
 */
public interface IPolicy<T> {
    // 租户标识常量
    public static final String TENANT = "tenant";

    // 数据权限标识常量
    public static final String DATA_PERMISSION = "dataPermission";

    // 行级权限标识常量
    public static final String ROW_PERMISSION = "rowPermission";

    // 数据集权限标识常量
    public static final String DATASET_PERMISSION = "datasetPermission";

    // 策略名称
    public String getPolicyName();

    // 策略值
    public String getPolicyValue();

    // 策略类型
    public String getPolicyType();

    public String getPolicyDesc();

    public String getPolicyCode();

    public String getPolicyGroup();

    public String getPolicyGroupDesc();

    public String getPolicyGroupCode();

    public IPolicy addPolicyCondition(PolicyCondition policyCondition);

    public IPolicy removePolicyCondition(PolicyCondition policyCondition);

    //策略条件，支持多条件
    public PolicyCondition[] getPolicyCondition();

    public static <T> IPolicy of(String policeName) {
        switch (policeName) {
            case "tenant":
                return new TenantPolicy();
            case "dataPermission":
                return new DataPermissionPolicy();
            case "rowPermission":
                return new RowPermissionPolicy();
        }

        return null;
    }


    void before(AbstractOperatorParameter target);

    void after();

}
